package com.poetize.plus.entity.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.poetize.plus.entity.po.Article;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zuosy
 * @created 2024/4/2 10:20
 */
public record HomeRecommendArticleVO(
        @Schema(description = "id")
        Long id,
        @Schema(description = "文章标题")
        String articleTitle,
        @Schema(description = "文章封面")
        String articleCover,
        @Schema(description = "发布时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        LocalDateTime createTime
) {
        /**
         * 实体类集合转推荐文章集合
         * @param articleList
         * @return
         */
        public static List<HomeRecommendArticleVO> convertRecommendArticle(List<Article> articleList){
                List<HomeRecommendArticleVO> result = new ArrayList<>();
                articleList.forEach(article -> {
                        HomeRecommendArticleVO vo = new HomeRecommendArticleVO(
                                article.getId(),
                                article.getArticleTitle(),
                                article.getArticleCover(),
                                article.getCreateTime());
                        result.add(vo);
                });
                return result;
        }
}
